using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Model;
using System;
using System.Collections.Generic;
using System.Data;
namespace HKB.Data.Bll
{
	public class Client
	{
		private readonly HKB.Data.Dal.Client dal = new HKB.Data.Dal.Client();
		private static Client _instance = null;
		public static Client instance
		{
			get
			{
				if (Client._instance == null)
				{
					Client._instance = new Client();
				}
				return Client._instance;
			}
		}
		public int GetMaxId()
		{
			return this.dal.GetMaxId();
		}
		public bool Exists(int ClientID)
		{
			return this.dal.Exists(ClientID);
		}
		public int Add(HKB.Data.Model.Client model)
		{
			return this.dal.Add(model);
		}
		public bool Update(HKB.Data.Model.Client model)
		{
			return this.dal.Update(model);
		}
		public bool Delete(int ClientID)
		{
			return this.dal.Delete(ClientID);
		}
		public bool DeleteList(string ClientIDlist)
		{
			return this.dal.DeleteList(ClientIDlist);
		}
		public HKB.Data.Model.Client GetModel(int ClientID)
		{
			return this.dal.GetModel(ClientID);
		}
		public HKB.Data.Model.Client GetModelByCache(int ClientID)
		{
			string cacheKey = "ClientModel-" + ClientID;
			object obj = DataCache.GetCache(cacheKey);
			if (obj == null)
			{
				try
				{
					obj = this.dal.GetModel(ClientID);
					if (obj != null)
					{
						int configInt = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(cacheKey, obj, System.DateTime.Now.AddMinutes((double)configInt), System.TimeSpan.Zero);
					}
				}
				catch
				{
				}
			}
			return (HKB.Data.Model.Client)obj;
		}
		public DataSet GetList(string strWhere)
		{
			return this.dal.GetList(strWhere);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return this.dal.GetList(Top, strWhere, filedOrder);
		}
		public System.Collections.Generic.List<HKB.Data.Model.Client> GetModelList(string strWhere)
		{
			DataSet list = this.dal.GetList(strWhere);
			return this.DataTableToList(list.Tables[0]);
		}
		public System.Collections.Generic.List<HKB.Data.Model.Client> DataTableToList(DataTable dt)
		{
			System.Collections.Generic.List<HKB.Data.Model.Client> list = new System.Collections.Generic.List<HKB.Data.Model.Client>();
			int count = dt.Rows.Count;
			if (count > 0)
			{
				for (int i = 0; i < count; i++)
				{
					HKB.Data.Model.Client client = this.dal.DataRowToModel(dt.Rows[i]);
					if (client != null)
					{
						list.Add(client);
					}
				}
			}
			return list;
		}
		public DataSet GetAllList()
		{
			return this.GetList("");
		}
		public int GetRecordCount(string strWhere)
		{
			return this.dal.GetRecordCount(strWhere);
		}
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return this.dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
		}
		public HKB.Data.Model.Client GetClientByClientName(string clientName, int owner)
		{
			return this.dal.GetClientByClientName(clientName, owner);
		}
	}
}
